<?php 
require 'Model.php';
class IndexModel extends Model{
	function __construct(){
		parent::__construct();
		$this->mod = 'books';
	}
	function getList(){
		$sql_vt="select * from booktype";
		$vt_list = $this->conn->query($sql_vt);
		//var_dump($vt_list);
		$v_list=array();
		foreach($vt_list as $one){
		    $sql="select * from {$this->mod} where bookid=".$one['bookid']." order by bid  limit 0,6 ";
		   // echo $sql."</br>";
		    $vlist=array();
		    $vlist['typename']=$one['typename'];
		    $vlist['bookid']=$one['bookid'];
		    $vlist['list']=$this->conn->query($sql);
		    $v_list[]=$vlist;
		}//var_dump($v_list);
		    return $v_list;
	}
	function getVideoType(){
		$sql_vt="select * from booktype";
		$data = $this->conn->query($sql_vt);
		//var_dump($data);
			return $data;
}
	function getVideoByHits(){
	 $sql_borrytime="select * from {$this->mod} order by borrytime desc limit 0,4";
	 $data = $this->conn->query($sql_borrytime);
			return $data;
	}
	function getVideoByDowntimes(){
		$sql_hittime="select * from {$this->mod} order by hittime desc limit 0,4";
		$data = $this->conn->query($sql_hittime);
			return $data;

	}
	function getVideoById($id){
		$sql="select * from {$this->mod} where bookid=".$id;
	    $data = $this->conn->query($sql);
		return $data;

	}
	function getTypeByTid($id){
		$sql="select typename from booktype where bookid={$id}";
	    $data = $this->conn->query($sql);
		return $data;

	}
	function getVideoByVid($id){
		$sql="select * from books where bid={$id}";
	    $data = $this->conn->query($sql);
	    $bid_list=array();
		foreach($data as $one){
		    $vlist=array();
		    $vlist['bid']=$one['bid'];
		    $vlist['bookname']=$one['bookname'];
		    $vlist['pic']=$one['pic'];
		    $vlist['intro']=$one['intro'];
		    $vlist['uploaddate']=$one['uploaddate'];
		    $vlist['uploadadmin']=$one['uploadadmin'];
		    $vlist['borrytime']=$one['borrytime'];
		    $vlist['hittime']=$one['hittime'];
		   
		    $bid_list=$vlist;
				return $bid_list;
		}
	}
}




 ?>